﻿<template>
  <div class="ynRd-container">
    <el-row :gutter="8" style="width: 100%; flex: 1">

      <el-col :span="3" :xs="24">
        <RegionTree ref="regionTreeRef" @node-click="nodeClick" />
      </el-col>
      <el-col :span="21" :xs="24" style="display: flex; flex-direction: column">

      <el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
      <el-form :model="queryParams" ref="queryForm" labelWidth="90">
        <el-row>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10">
            <el-form-item label="关键字">
              <el-input v-model="queryParams.searchKey" clearable="" placeholder="请输入模糊查询关键字"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="开始桩号">
              <el-input v-model="queryParams.start_stake_num" clearable="" placeholder="请输入开始桩号"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="结束桩号">
              <el-input v-model="queryParams.end_stake_num" clearable="" placeholder="请输入结束桩号"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="车道">
              <el-input v-model="queryParams.lane" clearable="" placeholder="请输入车道"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="监测长度">
              <el-input v-model="queryParams.length" clearable="" placeholder="请输入监测长度"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="rd最大值">
              <el-input v-model="queryParams.rd_max" clearable="" placeholder="请输入rd最大值"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="rd最小值">
              <el-input v-model="queryParams.rd_min" clearable="" placeholder="请输入rd最小值"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="rd平均数">
              <el-input v-model="queryParams.rd_average" clearable="" placeholder="请输入rd平均数"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="rd方差">
              <el-input v-model="queryParams.rd_variance" clearable="" placeholder="请输入rd方差"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="rd">
              <el-input v-model="queryParams.rd" clearable="" placeholder="请输入rd"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="rdi">
              <el-input v-model="queryParams.rdi" clearable="" placeholder="请输入rdi"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="评定">
              <el-input v-model="queryParams.pd" clearable="" placeholder="请输入评定"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="年度">
              <el-input v-model="queryParams.annual" clearable="" placeholder="请输入年度"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="类型">
              <el-input v-model="queryParams.type" clearable="" placeholder="请输入类型"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="项目ID">
              <el-input v-model="queryParams.pid" clearable="" placeholder="请输入项目ID"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="6" class="mb10">
            <el-form-item>
              <el-button-group style="display: flex; align-items: center;">
                <el-button type="primary"  icon="ele-Search" @click="handleQuery" v-auth="'ynRd:page'"> 查询 </el-button>
                <el-button icon="ele-Refresh" @click="() => queryParams = {}"> 重置 </el-button>
                <el-button icon="ele-ZoomIn" @click="changeAdvanceQueryUI" v-if="!showAdvanceQueryUI" style="margin-left:5px;"> 高级查询 </el-button>
                <el-button icon="ele-ZoomOut" @click="changeAdvanceQueryUI" v-if="showAdvanceQueryUI" style="margin-left:5px;"> 隐藏 </el-button>
                <el-button type="primary" style="margin-left:5px;" icon="ele-Plus" @click="openAddYnRd" v-auth="'ynRd:add'"> 新增 </el-button>
                
              </el-button-group>
            </el-form-item>
            
          </el-col>
        </el-row>
      </el-form>
    </el-card>
          <el-card class="full-table" shadow="hover" style="margin-top: 5px">
      <el-table
				:data="tableData"
				style="width: 100%"
				v-loading="loading"
				tooltip-effect="light"
				row-key="id"
                @sort-change="sortChange"
				border="">
        <el-table-column type="index" label="序号" width="55" align="center"/>
        <el-table-column  prop="roadName" label="路网名称"  width="140" align="center"/>
        <el-table-column prop="pid" label="所属路网ID" width="140"  show-overflow-tooltip="" />
        <el-table-column prop="type" label="类型" width="140"  show-overflow-tooltip="" />
        <el-table-column prop="start_stake_num" label="开始桩号" width="140"  show-overflow-tooltip="" />
        <el-table-column prop="end_stake_num" label="结束桩号" width="140"  show-overflow-tooltip="" />
        <el-table-column prop="lane" label="车道" width="140"  show-overflow-tooltip="" />
        <el-table-column prop="length" label="监测长度" width="140"  show-overflow-tooltip="" />
        <el-table-column prop="rd" label="rd" width="140"  show-overflow-tooltip="" />
        <el-table-column prop="rdi" label="rdi" width="140"  show-overflow-tooltip="" />
        <el-table-column prop="rd_max" label="rd最大值" width="140"  show-overflow-tooltip="" />
        <el-table-column prop="rd_min" label="rd最小值" width="140"  show-overflow-tooltip="" />
        <el-table-column prop="rd_average" label="rd平均数" width="140"  show-overflow-tooltip="" />
        <el-table-column prop="rd_variance" label="rd方差" width="140"  show-overflow-tooltip="" />
        <el-table-column prop="pd" label="评定" width="140"  show-overflow-tooltip="" />
        <el-table-column prop="annual" label="年度" width="140"  show-overflow-tooltip="" />
        <el-table-column label="操作" width="140" align="center" fixed="right" show-overflow-tooltip="" v-if="auth('ynRd:update') || auth('ynRd:delete')">
          <template #default="scope">
            <el-button icon="ele-Edit" size="small" text="" type="primary" @click="openEditYnRd(scope.row)" v-auth="'ynRd:update'"> 编辑 </el-button>
            <el-button icon="ele-Delete" size="small" text="" type="primary" @click="delYnRd(scope.row)" v-auth="'ynRd:delete'"> 删除 </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
				v-model:currentPage="tableParams.page"
				v-model:page-size="tableParams.pageSize"
				:total="tableParams.total"
				:page-sizes="[10, 20, 50, 100, 200, 500]"
				small=""
				background=""
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				layout="total, sizes, prev, pager, next, jumper"
	/>
      <printDialog
        ref="printDialogRef"
        :title="printYnRdTitle"
        @reloadTable="handleQuery" />
      <editDialog
        ref="editDialogRef"
        :title="editYnRdTitle"
        @reloadTable="handleQuery"
      />
    </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script lang="ts" setup="" name="ynRd">
  import { ref } from "vue";
  import { ElMessageBox, ElMessage } from "element-plus";
  import RegionTree from '/@/views/system/region/component/regionTree.vue';

  import { auth } from '/@/utils/authFunction';
  import { getDictDataItem as di, getDictDataList as dl } from '/@/utils/dict-utils';
  import { formatDate } from '/@/utils/formatTime';


  import printDialog from '/@/views/system/print/component/hiprint/preview.vue'
  import editDialog from '/@/views/main/ynRd/component/editDialog.vue'
  import { pageYnRd, deleteYnRd } from '/@/api/main/ynRd';

  const regionTreeRef = ref<InstanceType<typeof RegionTree>>();

  const showAdvanceQueryUI = ref(false);
  const printDialogRef = ref();
  const editDialogRef = ref();
  const loading = ref(false);
  const tableData = ref<any>([]);
  const queryParams = ref<any>({});
  const tableParams = ref({
    page: 1,
    pageSize: 10,
    total: 0,
  });

  const printYnRdTitle = ref("");
  const editYnRdTitle = ref("");

  // 改变高级查询的控件显示状态
  const changeAdvanceQueryUI = () => {
    showAdvanceQueryUI.value = !showAdvanceQueryUI.value;
  }
  

  // 查询操作
  const handleQuery = async () => {
    loading.value = true;
    var res = await pageYnRd(Object.assign(queryParams.value, tableParams.value));
    tableData.value = res.data.result?.items ?? [];
    tableParams.value.total = res.data.result?.total;
    loading.value = false;
  };

  // 列排序
  const sortChange = async (column: any) => {
	queryParams.value.field = column.prop;
	queryParams.value.order = column.order;
	await handleQuery();
  };

  // 打开新增页面
  const openAddYnRd = () => {
    editYnRdTitle.value = '添加车辙数据';
    editDialogRef.value.openDialog({});
  };

  // 打开打印页面
  const openPrintYnRd = async (row: any) => {
    printYnRdTitle.value = '打印车辙数据';
  }
  
  // 打开编辑页面
  const openEditYnRd = (row: any) => {
    editYnRdTitle.value = '编辑车辙数据';
    editDialogRef.value.openDialog(row);
  };

  // 删除
  const delYnRd = (row: any) => {
    ElMessageBox.confirm(`确定要删除吗?`, "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
  .then(async () => {
    await deleteYnRd(row);
    handleQuery();
    ElMessage.success("删除成功");
  })
  .catch(() => {});
  };

  // 改变页面容量
  const handleSizeChange = (val: number) => {
    tableParams.value.pageSize = val;
    handleQuery();
  };

  // 改变页码序号
  const handleCurrentChange = (val: number) => {
    tableParams.value.page = val;
    handleQuery();
  };
  // 树组件点击
  const nodeClick = async (node: any) => {
    // 创建一个新的查询参数对象
    const newQueryParams = { ...queryParams.value };
    newQueryParams.pid = node.id;
    newQueryParams.name = undefined;
    newQueryParams.code = undefined;

    // 更新 queryParams.value
    queryParams.value = newQueryParams;

    handleQuery();
  };
  handleQuery();
</script>
<style scoped>
:deep(.el-ipnut),
:deep(.el-select),
:deep(.el-input-number) {
	width: 100%;
}
</style>

